//
//  addViewController.m
//  StudentAddressbook
//
//  Created by 苗钧豪 on 16/7/25.
//  Copyright © 2016年 苗钧豪. All rights reserved.
//

#import "addViewController.h"

@interface addViewController ()

@end

@implementation addViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.translucent = YES;
    // Do any additional setup after loading the view.
    self.title = @"添加";
    _namefield = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 30)];
    _namefield.placeholder = @"姓名";
    [self.view addSubview:_namefield];
    
    _agefield = [[UITextField alloc]initWithFrame:CGRectMake(100, 200, 200, 30)];
    _agefield.placeholder = @"年龄";
    [self.view addSubview:_agefield];
    
    _genderfield = [[UITextField alloc]initWithFrame:CGRectMake(100, 300, 200, 30)];
    _genderfield.placeholder = @"性别";
    [self.view addSubview:_genderfield];
    
    _phonefield = [[UITextField alloc]initWithFrame:CGRectMake(100, 400, 200, 30)];
    _phonefield.placeholder = @"电话";
    [self.view addSubview:_phonefield];
    
    UIButton *btn = [UIButton buttonWithType:(UIButtonTypeSystem)];
    [btn setTitle:@"保存" forState:(UIControlStateNormal)];
    btn.backgroundColor = [UIColor orangeColor];
    [btn addTarget:self action:@selector(saveStudent) forControlEvents:(UIControlEventTouchUpInside)];
    btn.frame = CGRectMake(100, 500, 200, 30);
    [self.view addSubview:btn];
}
- (void)saveStudent {
    if (self.delegate && [self.delegate respondsToSelector:@selector(addStudent:age:gender:phoneNUmber:)]) {
        [self.delegate addStudent:self.namefield.text age:(NSInteger)self.agefield.text gender:self.genderfield.text phoneNUmber:self.phonefield.text];
    }
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
